package com.ljx.itbbs.server.article.service.handler;

import cn.hutool.extra.spring.SpringUtil;
import com.ljx.itbbs.server.article.service.ArticleService;
import com.ljx.itbbs.server.article.service.ArticleTagService;
import com.ljx.itbbs.server.article.service.ResourceService;
import com.ljx.itbbs.server.user.service.UserService;

import java.util.List;
import java.util.TimerTask;


/**
 * @Author: LiJunXi
 * @Description: 文章异步任务处理
 * @Date: 2024-03-24  09:53
 */
public class ArticleAsyncHandler {


    public static TimerTask increaseViewsNum(Long articleId) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtil.getBean(ArticleService.class).increaseViewsNum(articleId);
            }
        };
    }

    public static TimerTask increaseUserIntegralAndExp(Long userId, Long exp, Integer integral) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtil.getBean(UserService.class).increaseUserExp(userId, exp);
                SpringUtil.getBean(UserService.class).increaseUserIntegral(userId, integral);
            }
        };
    }

    public static TimerTask increaseResourceDownloadNum(Long resourceId) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtil.getBean(ResourceService.class).increaseDownloadNum(resourceId);
            }
        };
    }


}
